package com.seuic.hnapps.project;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.seuic.hnapps.BaseActivity;
import com.seuic.hnapps.R;
import com.seuic.hnapps.SquareLayout;
import com.seuic.hnapps.posdsdk.pos_func.PosFuncs;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * isjingkai
 * 2019年7月20日10:40:27
 * 首页
 */
public class HomeActivity extends BaseActivity {
    //        60.212.3.49
//
//        端口3551

    PosFuncs posFuncs;

    @BindView(R.id.base_back_btn)
    LinearLayout baseBackBtn;
    @BindView(R.id.base_title_text)
    TextView baseTitleText;
    @BindView(R.id.to_help_farmers_withdrawals_Btn)
    SquareLayout toHelpFarmersWithdrawalsBtn;
    @BindView(R.id.cash_remittance_Btn)
    SquareLayout cashRemittanceBtn;
    @BindView(R.id.remittance_Transfer_Btn)
    SquareLayout remittanceTransferBtn;
    @BindView(R.id.special_Service_Btn)
    SquareLayout specialServiceBtn;
    @BindView(R.id.an_inter_bank_business_Btn)
    SquareLayout anInterBankBusinessBtn;
    @BindView(R.id.charge_agency_Btn)
    SquareLayout chargeAgencyBtn;
    @BindView(R.id.operator_Service_Btn)
    SquareLayout operatorServiceBtn;
    @BindView(R.id.business_Statistics_Btn)
    SquareLayout businessStatisticsBtn;
    @BindView(R.id.inquiry_Business_Btn)
    SquareLayout inquiryBusinessBtn;
    @BindView(R.id.home_1layout)
    LinearLayout home1layout;
    @BindView(R.id.home_2layout)
    LinearLayout home2layout;
    @BindView(R.id.home_3layout)
    LinearLayout home3layout;
    @BindView(R.id.sign_out_nobtn)
    Button signOutNobtn;
    @BindView(R.id.sign_out_okbtn)
    Button signOutOkbtn;
    @BindView(R.id.home_qt_layout)
    CardView homeQtLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        ButterKnife.bind(this);
        baseBackBtn.setVisibility(View.INVISIBLE);
        this.setTitleText(R.id.base_title_text, "(   " + "惠农金服APP" + "   )");
        Toast.makeText(this, "签到成功", Toast.LENGTH_SHORT).show();
        posFuncs = PosFuncs.getInstace();
        posFuncs.init(this);
    }

    //     用来计算返回键的点击间隔时间
    private long exitTime = 0;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                //弹出提示，可以有多种方式
                home1layout.setVisibility(View.GONE);
                home2layout.setVisibility(View.GONE);
                home3layout.setVisibility(View.GONE);
                homeQtLayout.setVisibility(View.VISIBLE);
                exitTime = System.currentTimeMillis();
            } else {
//                finish();
            }
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

    @OnClick({
            R.id.to_help_farmers_withdrawals_Btn, R.id.cash_remittance_Btn,
            R.id.remittance_Transfer_Btn, R.id.special_Service_Btn,
            R.id.an_inter_bank_business_Btn, R.id.charge_agency_Btn,
            R.id.operator_Service_Btn, R.id.business_Statistics_Btn,
            R.id.inquiry_Business_Btn,
            R.id.sign_out_nobtn, R.id.sign_out_okbtn
    })


    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.to_help_farmers_withdrawals_Btn:
                //助农取款
                Toast.makeText(this, "助农取款", Toast.LENGTH_SHORT).show();
                Intent intent_ToHelp = new Intent(this, ToHelpFarmersWithdrawalsActivity.class);
                startActivity(intent_ToHelp);
                break;
            case R.id.cash_remittance_Btn:
                //现金汇款
                Toast.makeText(this, "现金汇款", Toast.LENGTH_SHORT).show();
                Intent intent_cash = new Intent(this, CashRemittanceActivity.class);
                startActivity(intent_cash);
                break;
            case R.id.remittance_Transfer_Btn:
                //转账汇款
                Toast.makeText(this, "转账汇款", Toast.LENGTH_SHORT).show();
                Intent intent_remittance = new Intent(this, RemittanceTransferActivity.class);
                startActivity(intent_remittance);
//                Toast.makeText(this, "该功能尚未开通，敬请期待", Toast.LENGTH_SHORT).show();
                break;
            case R.id.special_Service_Btn:
                //特殊业务
                Toast.makeText(this, "特殊业务", Toast.LENGTH_SHORT).show();
//                Toast.makeText(this, "该功能尚未开通，敬请期待", Toast.LENGTH_SHORT).show();
                Intent intent_special = new Intent(this, SpecialServiceActivity.class);
                startActivity(intent_special);
                break;
            case R.id.an_inter_bank_business_Btn:
                //跨行业务
                Toast.makeText(this, "该功能尚未开通，敬请期待", Toast.LENGTH_SHORT).show();
//                Intent intent_an_inter = new Intent(this, AninterbankBusinessBtn.class);
//                startActivity(intent_an_inter);
                break;
            case R.id.charge_agency_Btn:
                //代理缴费
                Toast.makeText(this, "代理缴费", Toast.LENGTH_SHORT).show();
//                Toast.makeText(this, "该功能尚未开通，敬请期待", Toast.LENGTH_SHORT).show();
                Intent intent_charge = new Intent(this, ChargeAgencyActivity.class);
                startActivity(intent_charge);

                break;
            case R.id.operator_Service_Btn:
                //操作员业务
                Toast.makeText(this, "操作员业务", Toast.LENGTH_SHORT).show();
                Intent intent_operator = new Intent(this, OperatorServiceActivity.class);
                startActivity(intent_operator);
                break;
            case R.id.business_Statistics_Btn:
                //惠农业务
                Toast.makeText(this, "惠农业务", Toast.LENGTH_SHORT).show();
                Intent intent_business = new Intent(this, BusinessStatisticsActivity.class);
                startActivity(intent_business);
                break;
            case R.id.inquiry_Business_Btn:
                //查询业务
                Toast.makeText(this, "查询业务", Toast.LENGTH_SHORT).show();
                Intent intent_inquiry = new Intent(this, InquiryBusinessActivity.class);
                startActivity(intent_inquiry);
                break;
            case R.id.sign_out_nobtn:
                home1layout.setVisibility(View.VISIBLE);
                home2layout.setVisibility(View.VISIBLE);
                home3layout.setVisibility(View.VISIBLE);
                homeQtLayout.setVisibility(View.GONE);
                break;
            case R.id.sign_out_okbtn:
//                Intent i = new Intent("action.exit");
//                sendBroadcast(i);
                Intent intent = new Intent(this, LogingActivity.class);
                startActivity(intent);
                this.finish();
                break;
        }
    }


}
